define(["require",'config/appregister',"business/special/service/http","jquery","business/services/detailNavComp","business/services/filter"], function(require, app, httpServices){
	app.controller('specialMaterialCtrl',function($scope, $rootScope, $state, $stateParams){
		if(!angular.isUndefined($stateParams.catalogId)) {
			var catalogId=$stateParams.catalogId;
		}
		if(!angular.isUndefined($stateParams.type)) {
			var type=$stateParams.type;
		}
		if(catalogId==1){
			$scope.bannerSrc='./them/special/banner1.jpg';
		}else if(catalogId==2){
			$scope.bannerSrc='./them/special/banner2.jpg';
		}else if(catalogId==3){
			$scope.bannerSrc='./them/special/banner3.jpg';
		}else if(catalogId==4){
			$scope.bannerSrc='./them/special/banner4.jpg';
		}else if(catalogId=='5e199b0c353e476a90481464a4afb0bb'){
			$scope.bannerSrc='./them/special/banner5.jpg';
		}

		$scope.timeFlag=true;
		$scope.downloadFlag=false;
		$scope.timeSrc='them/imag/top-blue-arrow.png';
		$scope.downloadSrc='them/img/bottom.png';
		$scope.orderByTime=function(){
			if($scope.timeFlag){
				$scope.timeFlag=false;
				$scope.timeSrc='them/img/bottom.png';
			}else{
				$scope.timeFlag=true;
				$scope.timeSrc='them/imag/top-blue-arrow.png';
			}
			getList(type,catalogId,1,12);
		};
		$scope.orderByDownload=function(){
			if($scope.downloadFlag){
				$scope.downloadFlag=false;
				$scope.downloadSrc='them/img/bottom.png';
			}else{
				$scope.downloadFlag=true;
				$scope.downloadSrc='them/imag/top-blue-arrow.png';
			}
			getList(type,catalogId,1,12);
		};

		getList(type,catalogId,1,12);
		function getList(type,id,pageNum,num){
			var req = {
				type:"GET",
				uri:'getListByCatalogId',
				data:{
					type:type,
					catalogId:id,
					pageNo:pageNum,
					pageSize:num,
					time:$scope.timeFlag,
					browseCount:$scope.downloadFlag
				}
			};
			httpServices.specialHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function(){
					if(data.code == 0) {
						$scope.category=data.data.category;
						$scope.title=$scope.category.subjectName+'——'+$scope.category.subtitle;
						$scope.data=data.data;
						$scope.pageNO=data.data.Pagination.pageNo;
						$scope.dataList=data.data.list;
						for(var item in $scope.dataList){
							getImgSrc($scope.dataList[item]);
						}
						paginationConf();
					}else {
						console.log(data.msg)
					}
				});
			}).error(function(){
				console.log("分页请求失败");
			});
		};

		function getImgSrc(item){
			switch (item.typeId){
				case 1:
					item.imgSrc="them/imag/doc-small.png";
					break;
				case 11:
					item.imgSrc="them/imag/pdf-small.png";
					break;
				case 12:
					item.imgSrc="them/imag/txt-small.png";
					break;
				case 14:
					item.imgSrc="them/imag/xls-small.png";
					break;
				case 15:
					item.imgSrc="them/imag/ppt-small.png";
					break;
				case 16:
					item.imgSrc="them/imag/rar-small.png";
					break;
				case 17:
					item.imgSrc="them/imag/swf-small.png";
					break;
				case 18:
					item.imgSrc="them/imag/jpeg-small.png";
					break;
				case 19:
					item.imgSrc="them/imag/chm-small.png";
					break;
				case 20:
					item.imgSrc="them/imag/dwg-small.png";
					break;
				case 21:
					item.imgSrc="them/imag/caj-small.png";
					break;
			}
		}

		function paginationConf(){
			$scope.paginationConf = {
				currentPage:$scope.pageNO ,
				totalItems: $scope.data.Pagination.totalCount,
				//每页预览条数
				itemsPerPage: 12,
				//分页总数
				numberOfPages: Math.ceil($scope.data.Pagination.totalCount /12),
				// 实际分页长度
				pagesLength: 5,
				perPageOptions: [12, 24, 36, 48, 60],
				onChange:function(currentPage) {
					if(currentPage) {
						$scope.paginationConf.currentPage= currentPage;
					}
					$scope.list = [];
					$scope.pageNO = $scope.paginationConf.currentPage;
					getList(type,catalogId,$scope.pageNO,12);
				}
			};
		}

	})
});